package com.wn.servlet.req;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * @author yellow Docter
 * @date 2022 -06-29
 * @desc
        HttpServletRequest 可以页面跳转  (请求转发 )
        可以数据传递:
              AServlet 把数据传递到  BServlet
        域对象: 内部有一个map 把数据封装到map中进行传递


 */
@WebServlet("/demo03")
public class Demo03Servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("我不能处理...");

        // 01 拿到分发器  你要分发给谁  写路径
        // /项目的访问/资源路径
        RequestDispatcher dispatcher = req.getRequestDispatcher("/demo04");

        req.setAttribute("key1","王语嫣");
        req.setAttribute("key2",30);
        req.setAttribute("key3", new Date() );

        //02 转发  forward 转发操作
        dispatcher.forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}

